<Project>
  <Import Project="..\Directory.Build.targets" />

  <PropertyGroup>
    <!-- Central place to set the versions of all nuget packages produced in the repo -->
    <PackageVersion Condition="'$(PackageVersion)' == ''">$(ProductVersion)</PackageVersion>
    <StableVersion Condition="'$(StabilizePackageVersion)' == 'true' and '$(StableVersion)' == '' and '$(PreReleaseVersionLabel)' != 'servicing'">$(PackageVersion)</StableVersion>
    <StableVersion Condition="'$(IsShippingPackage)' != 'true' and '$(MSBuildProjectExtension)' == '.pkgproj'"></StableVersion>
  </PropertyGroup>

  <Import Project="$(NuGetPackageRoot)\microsoft.dotnet.build.tasks.packaging\$(MicrosoftDotNetBuildTasksPackagingVersion)\build\Microsoft.DotNet.Build.Tasks.Packaging.targets" />

  <!--
    Finds symbol files and injects them into the package build.
  -->
  <Target Name="GetSymbolPackageFiles" BeforeTargets="GetPackageFiles">
    <ItemGroup Condition="'$(SymbolsSuffix)' != ''">
      <AdditionalLibPackageExcludes Include="%2A%2A\%2A$(SymbolsSuffix)"/>
    </ItemGroup>

    <ItemGroup>
      <NativeWithSymbolFile Include="@(NativeBinary)" Condition="'$(PackageTargetRuntime)'!=''">
        <TargetPath>runtimes/$(PackageTargetRuntime)/native</TargetPath>
      </NativeWithSymbolFile>
      <NativeWithSymbolFile Include="@(ArchitectureSpecificToolFile)">
        <TargetPath>tools</TargetPath>
      </NativeWithSymbolFile>
    </ItemGroup>

    <ItemGroup>
      <File Include="@(NativeWithSymbolFile)" />
    </ItemGroup>

    <ItemGroup>
      <!-- On Windows, trim ".dll" before adding ".pdb". -->
      <WindowsNativeFile Include="@(NativeWithSymbolFile)"
                         Condition="'%(NativeWithSymbolFile.Extension)'=='.dll' OR '%(NativeWithSymbolFile.Extension)'=='.exe'" />
      <WindowsSymbolFile Include="@(WindowsNativeFile -> '%(RootDir)%(Directory)PDB\%(Filename).pdb')" />
      <!-- Crossgened files (on windows) have both a *.pdb and a *.ni.pdb symbol file.  Include the *.ni.pdb file as well if it exists. -->
      <WindowsSymbolFile Include="@(WindowsNativeFile -> '%(RootDir)%(Directory)PDB\%(Filename).ni.pdb')" />

      <!--
        Search for all xplat symbol file extensions on every xplat native binary. Some binaries have
        no ".so" or ".dylib" extension, so we can't tell which convention its symbol files would
        use. On xplat, the symbol extension is simply appended.
      -->
      <NonWindowsNativeFile Include="@(NativeWithSymbolFile)"
                            Exclude="@(WindowsNativeFile)" />

      <NonWindowsSymbolFile Include="@(NonWindowsNativeFile -> '%(Identity)$(SymbolsSuffix)')" />

      <ExistingWindowsSymbolFile Include="@(WindowsSymbolFile)" Condition="Exists('%(Identity)')" />
      <ExistingNonWindowsSymbolFile Include="@(NonWindowsSymbolFile)" Condition="Exists('%(Identity)') AND '$(SkipPackagingXplatSymbols)'!='true'" />

      <!-- Include all found symbols. -->
      <File Include="@(ExistingWindowsSymbolFile);@(ExistingNonWindowsSymbolFile)">
        <IsSymbolFile>true</IsSymbolFile>
      </File>
    </ItemGroup>

    <PropertyGroup>
      <NeedsPlaceholderPdb Condition="'@(ExistingNonWindowsSymbolFile)'!='' AND '@(ExistingWindowsSymbolFile)'==''">true</NeedsPlaceholderPdb>
    </PropertyGroup>

    <ItemGroup>
      <File Include="$(MSBuildThisFileDirectory)\_.pdb"
            Condition="'$(NeedsPlaceholderPdb)'=='true' AND '$(PackageTargetRuntime)'!=''">
        <TargetPath>runtimes/$(PackageTargetRuntime)/native</TargetPath>
        <IsSymbolFile>true</IsSymbolFile>
      </File>
    </ItemGroup>
  </Target>

</Project>
